<template>
  <div class="divBox">
    <el-card class="box-card">
      <el-form inline size="small" @submit.native.prevent>
        <el-form-item label="日志标题：">
          <el-input v-model="listPram.title" placeholder="请输入日志标题" clearable class="selWidth"/>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" size="mini" type="primary" @click="handleSearch">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="listData.list" v-loading="loading" size="mini" :header-cell-style=" {fontWeight:'bold',background:'#f8f8f9',color: '#515a6e',height:'40px'}" border>
        <el-table-column
          prop="id"
          label="ID"
          width="50"
        />
        <el-table-column label="日志类型" prop="typeText" min-width="100"/>
        <el-table-column label="日志标题" prop="title" min-width="100"/>
        <el-table-column label="IP地址" prop="ipSources" min-width="100"/>
        <el-table-column label="操作IP地址" prop="remoteAddr" min-width="100">
        </el-table-column>
        <el-table-column label="操作用户" prop="userName" min-width="100">
        </el-table-column>
        <el-table-column label="创建时间" prop="createTime" min-width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.createTime | filterEmpty }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="100"  fixed="right">
          <template slot-scope="scope">
<!--            <el-button icon="el-icon-edit" type="primary" size="mini" @click="onDetails(scope.row)" v-hasPermi="['admin:system:log:detail']">日志详情</el-button>-->
            <el-button icon="el-icon-delete" type="danger" size="mini" @click="handlerOpenDel(scope.row)" v-hasPermi="['admin:system:log:delete']">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="listPram.page"
        :page-sizes="constants.page.limit"
        :layout="constants.page.layout"
        :total="listData.count"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
  </div>
</template>

<script>
import * as categoryApi from "@/api/categoryApi.js";
import * as roleApi from '@/api/role.js'
import edit from './edit'
import { deleteLog, sysLog } from '@/api/logApi'
import * as computerApi from '@/api/computer'
export default {
  // name: "index"
  components: { edit },
  data() {
    return {
      constants:this.$constants,
      loading:false,
      listData: { list: [] },
      listPram: {
        title: '',
        adminId:0,
        page: 1,
        limit: this.$constants.page.limit[0]
      },
      treeList: [],
      roleList: [],
      menuList: [],
      editDialogConfig: {
        visible: false,
        isCreate: 0, // 0=创建，1=编辑
        editData: {}
      }
    }
  },
  mounted() {
    this.handleGetAdminList()
   this.handleGetRoleList() //用于筛选条件中角色下拉
  },
  methods: {
    handleSearch() {
      this.listPram.page = 1
      this.handleGetAdminList()
    },
    handleSizeChange(val) {
      this.listPram.limit = val
      this.handleGetAdminList()
      this.handleGetRoleList(this.listPram)
    },
    handleCurrentChange(val) {
      this.listPram.page = val
      this.handleGetAdminList()
      this.handleGetRoleList(this.listPram)
    },
    handleGetRoleList() {
      const _pram = {
        page: 1,
        limit: this.constants.page.limit[4],
        status: 1
      }
      roleApi.getRoleList(_pram).then(data => {
        this.roleList = data
      })
    },

    //获取部门列表
    handlerGetTreeList() {
      const _pram = {
        name: '',
        page: 1,
        limit: this.constants.page.limit[4]
      }

      this.loading = true
      categoryApi.treeCategroy(_pram, 3).then(data => {
        this.treeList = data.list
        this.loading = false
      }).catch(()=>{
        this.loading = false
      })
    },
    // 详情
    onDetails(id){
      this.id = id
      this.Visible = true
    },
    hideEditDialog() {
      this.Visible = false
      this.handleGetPhotoList()
    },
    handlerOpenDel(rowData) {
      console.log(rowData)
      this.$confirm('确认删除当前数据').then(() => {
        const _pram = { id: rowData.id}
        deleteLog(_pram).then(data => {
          this.$message.success('删除数据成功')
          this.handleGetAdminList()
        })
      })
    },
    handleGetAdminList() {
      sysLog( this.listPram ).then(data => {
        this.listData = data
      })
    },
    handleGetPhotoList() {
      sysLog( this.listPram ).then(data => {
        this.listData = data
      })
    },
    handlerOpenEdit(isCreate, editDate) {
      this.editDialogConfig.editData = editDate
      this.editDialogConfig.isCreate = isCreate
      this.editDialogConfig.visible = true
    },
    resetQuery(){
      this.listPram.title = '';
      this.handleGetAdminList()
    }
  }
}
</script>

<style scoped>

</style>
